<!DOCTYPE html>
<html>
<head>
	<title>购物车加减</title>
	<meta charset="utf-8">
	<style type="text/css">
	div{
		height: 30px;
	}
	input{
		width: 50px;
		height:32px;
		background: white;
		border:1px solid #CCC;
		float: left;
	}
	span{
		width: 100px;
		height: 30px;
		text-align: center;
		display:inline-block;
		border:1px solid #CCC;
		line-height: 30px;
		float: left;
	}
</style>
</head>
<body>
	<div>
		<input  type="button" value="-" onclick="less()">
		<span>1</span>
		<input type="button" value="+" onclick="add()">
	</div>

</body>
<script type="text/javascript">
	var span=document.getElementsByTagName('span');
	var num=parseInt(span[0].innerHTML);//拿到数字
	//购买数量只能在0-100
	function less(){
		if (num==1) return;
		num--;
		span[0].innerHTML=num;
	}
	function add(){
		if(num>=100)return;
		num++;
		span[0].innerHTML=num;
	}
</script>
<ml>
